package rr18.rr181.rr181.rr18.plugin.list;

import com.kingdee.util.StringUtils;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.filter.CompareTypeEnum;
import kd.bos.filter.FilterColumn;
import kd.bos.form.IFormView;
import kd.bos.form.IPageCache;
import kd.bos.form.ShowType;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.*;
import kd.bos.list.BillList;
import kd.bos.list.IListView;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.sdk.plugin.Plugin;

import java.util.Iterator;
import java.util.List;

/**
 * 标准单据列表插件
 */
public class DemoListPlugin04 extends AbstractListPlugin implements Plugin {

    @Override
    public void billListHyperLinkClick(HyperLinkClickArgs args) {
        super.billListHyperLinkClick(args);
        String key = args.getFieldName();
        if("material_masterid_name".equals(key)){
            args.setCancel(true);//取消单据详情页面打开
            int rowIndex = args.getRowIndex();
            BillListHyperLinkClickEvent event = (BillListHyperLinkClickEvent)args.getHyperLinkClickEvent();
            ListSelectedRow currentRow = event.getCurrentRow();//获取当前点击行
            Object entryPrimaryKeyValue = currentRow.getEntryPrimaryKeyValue();//获取单据体ID
            // QFilter qFilter = new QFilter("entryentity.id", QFilter.equals, entryPrimaryKeyValue);
            DynamicObject kdecPurApply = QueryServiceHelper.queryOne(
                    "kdec_pur_apply",
                    "entryentity.kdec_materiel.id",
                    new QFilter[]{new QFilter("entryentity.id", QFilter.equals, entryPrimaryKeyValue)}
            );//因为列表界面只能获取id，使用装填，单据状态字段，其他需要通过orm框架查出
            long aLong = kdecPurApply.getLong("entryentity.kdec_materiel.id");
            BillShowParameter billShowParameter = new BillShowParameter();
            billShowParameter.setFormId("bd_materiel");
            billShowParameter.setPkId(aLong);
            billShowParameter.getOpenStyle().setShowType(ShowType.Modal);
            billShowParameter.setStatus(OperationStatus.VIEW);
            this.getView().showForm(billShowParameter);
        }
    }

    @Override
    public void itemClick(ItemClickEvent evt) {
        super.itemClick(evt);
        BillList billList =  this.getView().getControl(AbstractListPlugin.BILLLISTID);
    }
}